﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.meeting.manage
{
    public partial class manage : ModulePage
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            string url = (Request.QueryString["refer"] != null) ? Request.QueryString["refer"].ToString() : "meeting_wait.aspx";
            int meetingId = (Request.QueryString["meeting_id"] != null) ? int.Parse(Request.QueryString["meeting_id"]) : 0;
            int operation = (Request.QueryString["operation"] != null) ? int.Parse(Request.QueryString["operation"]) : 1;
            MeetingDao dao = new MeetingDao();
            DataTable table = dao.SelectByMeetingId(base.Conn, meetingId);
            if (table.Rows.Count == 0)
            {
                this.litMessage.Text = base.ShowError("无会议记录", url);
            }
            else
            {
                string str2 = (table.Rows[0]["Proposer"] != DBNull.Value) ? table.Rows[0]["Proposer"].ToString() : "";
                string str3 = (table.Rows[0]["Attendee"] != DBNull.Value) ? table.Rows[0]["Attendee"].ToString() : "";
                string str4 = (table.Rows[0]["Topic"] != DBNull.Value) ? table.Rows[0]["Topic"].ToString() : "";
                bool isSms = Convert.ToBoolean(table.Rows[0]["SmsRemind"].ToString());
                bool isMobile = Convert.ToBoolean(table.Rows[0]["MobileRemind"].ToString());
                SmsDao dao2 = new SmsDao();
                SmsData data = new SmsData();
                data.FromId = base.User.Identity.Name;
                data.SendTime = DateTime.Now;
                switch (operation)
                {
                    case 0:
                        dao.Manage(base.Conn, meetingId, operation);
                        if (isSms || isMobile)
                        {
                            data.Type = 8;
                            data.ToId = str2;
                            data.Content = "您的会议申请已被撤销！";
                            data.Url = "/general/meeting/apply/query.aspx?status=2";
                            dao2.BizSend(base.Conn, data, isSms, isMobile);
                        }
                        break;

                    case 1:
                        dao.Manage(base.Conn, meetingId, operation);
                        data.Type = 8;
                        data.ToId = str2;
                        data.Content = "您的会议申请已被批准！";
                        data.Url = "/general/meeting/apply/meeting_ok.aspx";
                        dao2.BizSend(base.Conn, data, true, false);
                        if ((isSms || isMobile) && (str3 != string.Empty))
                        {
                            data.Type = 8;
                            data.ToId = string.Empty;
                            data.ToIdList = str3;
                            data.Content = "您有新的会议需要参加！\n主题:" + str4;
                            data.Url = "/general/meeting/query/index.aspx";
                            dao2.BizSend(base.Conn, data, isSms, isMobile);
                        }
                        break;

                    case 2:
                        dao.Manage(base.Conn, meetingId, operation);
                        if (isSms || isMobile)
                        {
                            data.Type = 8;
                            data.ToId = str2;
                            data.Content = "您的会议申请未被批准！";
                            data.Url = "/general/meeting/query/index.aspx";
                            dao2.BizSend(base.Conn, data, isSms, isMobile);
                        }
                        break;
                }
                base.CloseConn();
                Response.Redirect(url);
            }
        }
 

    }
}
